package ioc13;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.*;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/7 11:42
 * Version:1.0-SNAPSHOT
 */
public class Test {

    public static void main(String[] args) throws IOException {
//        File file = new File("");
//        Resource resource = new ClassPathResource("ioc13/a.txt");
//        File file = resource.getFile();

//        InputStream in = resource.getInputStream();
//        BufferedReader br = new BufferedReader(new InputStreamReader(in));
//        System.out.println(br.readLine());

        ApplicationContext ac = new ClassPathXmlApplicationContext("ioc13/spring.xml");
        // 参数中的关键字classpath表示在类加载路径下查找对应的文件
//        Resource resource = ac.getResource("classpath:ioc13/a.txt");

        SomeBean someBean = (SomeBean) ac.getBean("someBean");
        Resource resource = someBean.getResource();

        InputStream in = resource.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        System.out.println(br.readLine());
    }

}
